package com.example.myapplication;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 类描述:
 * 创建人:   tangchao$
 * 创建时间: 2021/7/20$ 8:44 AM$
 * 联系方式: 419704299@qq.com
 * 修改人:   tangchao$
 * 修改时间: 2021/7/20$ 8:44 AM$
 * 修改备注:  [说明本次修改内容]
 */
public class TestPoolExecutor {
    public static void main(String[] args) {
        test1();
    }

    public static void test1() {
//        SynchronousQueue queue = new SynchronousQueue();
//        LinkedBlockingDeque queue = new LinkedBlockingDeque(1);
        ArrayBlockingQueue queue = new ArrayBlockingQueue(1);

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                60, TimeUnit.SECONDS, queue);
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务1=" + Thread.currentThread());
                while (true) {
                }
            }
        });
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务2=" + Thread.currentThread());

            }
        });
        threadPoolExecutor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务3=" + Thread.currentThread());

            }
        });
    }
}
